home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12333 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help with C Date/Time Calc
  5. Date: Sat, 30 Mar 96 17:44:03 GMT
  6. Organization: none
  7. Message-ID: <828207843snz@genesis.demon.co.uk>
  8. References: <4irm8d$bev@dfw-ixnews5.ix.netcom.com> <4it4ru$h9c@fohnix.metronet.com> <1996Mar24.201410.14507@sq.com>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <1996Mar24.201410.14507@sq.com> msb@sq.com "Mark Brader" writes:
  15.  
  16. >Keith Zawila (kzawila@ix.netcom.com) wrote:
  17. >> > I have the total number of seconds that have elapsed since 1/1/70,
  18. >> > and need to calculate the current date/time.
  19. >Stan Milam (milam@fohnix.metronet.com) answered:
  20. >> Check your manual for time(), localtime(), strftime(), ctime(), gmtime(), 
  21. >> and mktime(). ...
  22. >
  23. >Note that those functions work with an arithmetic type called time_t,
  24. >which represents calendar times (i.e. date and time) in a manner NOT
  25. >specified by the C standard.  On UNIX systems, this manner happens to
  26. >be "the total number of seconds that have elapsed since 1/1/70".  Keith
  27. >is probably using a UNIX system or he wouldn't have asked that particular
  28. >question; if so, Stan has answered it.
  29.  
  30. Stan's answer needn't be taken as Unix specific e.g. consider:
  31.  
  32.     time_t timeval;
  33.     struct tm tmbuf;
  34.  
  35.     tmbuf.tm_sec = seconds_since_1_1_70;
  36.     tmbuf.tm_min = 0;
  37.     tmbuf.tm_hour = 0;
  38.     tmbuf.tm_mday = 1;
  39.     tmbuf.tm_mon = 0;
  40.     tmbuf.tm_year = 70;
  41.     tmbuf.tm_isdst = -1;
  42.  
  43.     timeval = mktime(&tmbuf);
  44.  
  45. The 2 issues here are:
  46.  
  47. 1. Whether the time can be represented in a time_t value (you cn test the
  48.    return code of mkttime).
  49.  
  50. 2. Whether seconds_since_1_1_70 can be represented by an int since the
  51.    struct tm members are ints. If not you can help it out by breaking things
  52.    down a bit, say into seconds, minutes and days.
  53.  
  54. -- 
  55. -----------------------------------------
  56. Lawrence Kirby | fred@genesis.demon.co.uk
  57. Wilts, England | 70734.126@compuserve.com
  58. -----------------------------------------
  59.